package com.googlecode.yatspec.parsing;

import com.googlecode.totallylazy.Sequence;
import com.googlecode.yatspec.state.TestMethod;
import org.junit.Test;

import java.lang.reflect.Method;
import java.util.List;

import static com.googlecode.totallylazy.Methods.annotation;
import static com.googlecode.totallylazy.Predicates.notNullValue;
import static com.googlecode.totallylazy.Predicates.where;
import static com.googlecode.totallylazy.Sequences.sequence;

public class TestParser {

    public static List<TestMethod> parseTestMethods(Class aClass) throws Exception {
        final Sequence<Method> methods = getMethods(aClass);
        TestMethodCollector testMethodCollector = TestMethodCollectors.create(aClass);
        return testMethodCollector.collectTestMethods(aClass, methods).toList();
    }

    private static Sequence<Method> getMethods(Class aClass) {
        return sequence(aClass.getMethods()).filter(where(annotation(Test.class), notNullValue()));
    }

}
